package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ConstractOwner;
import com.ruoyi.system.service.IConstractOwnerService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业主管理Controller
 * 
 * @author ruoyi
 * @date 2022-04-04
 */
@Controller
@RequestMapping("/system/owner")
public class ConstractOwnerController extends BaseController
{
    private String prefix = "system/owner";

    @Autowired
    private IConstractOwnerService constractOwnerService;

    @RequiresPermissions("system:owner:view")
    @GetMapping()
    public String owner()
    {
        return prefix + "/owner";
    }

    /**
     * 查询业主管理列表
     */
    @RequiresPermissions("system:owner:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ConstractOwner constractOwner)
    {
        startPage();
        List<ConstractOwner> list = constractOwnerService.selectConstractOwnerList(constractOwner);
        return getDataTable(list);
    }

    /**
     * 导出业主管理列表
     */
    @RequiresPermissions("system:owner:export")
    @Log(title = "业主管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ConstractOwner constractOwner)
    {
        List<ConstractOwner> list = constractOwnerService.selectConstractOwnerList(constractOwner);
        ExcelUtil<ConstractOwner> util = new ExcelUtil<ConstractOwner>(ConstractOwner.class);
        return util.exportExcel(list, "业主管理数据");
    }

    /**
     * 新增业主管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存业主管理
     */
    @RequiresPermissions("system:owner:add")
    @Log(title = "业主管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ConstractOwner constractOwner)
    {
        return toAjax(constractOwnerService.insertConstractOwner(constractOwner));
    }

    /**
     * 修改业主管理
     */
    @RequiresPermissions("system:owner:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ConstractOwner constractOwner = constractOwnerService.selectConstractOwnerById(id);
        mmap.put("constractOwner", constractOwner);
        return prefix + "/edit";
    }

    /**
     * 修改保存业主管理
     */
    @RequiresPermissions("system:owner:edit")
    @Log(title = "业主管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ConstractOwner constractOwner)
    {
        return toAjax(constractOwnerService.updateConstractOwner(constractOwner));
    }

    /**
     * 删除业主管理
     */
    @RequiresPermissions("system:owner:remove")
    @Log(title = "业主管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(constractOwnerService.deleteConstractOwnerByIds(ids));
    }
}
